/**
 * Bakalarska prace - Inteligentni budik
 * @package sleepCatcher
 * @file FormSettingsSleepLength.cpp
 * @author Jan Pesava - xpesav00
 * @email xpesav00@stud.fit.vutbr.cz
 * @date 24. 12. 2011
 */

#include "forms/FormSettingsSleepLength.h"
#include "SCFormManager.h"
#include "SCSettings.h"
#include "SCTranslator.h"

FormSettingsSleepLength::FormSettingsSleepLength()
{
}

FormSettingsSleepLength::~FormSettingsSleepLength()
{
}

bool
FormSettingsSleepLength::Initialize()
{
	Construct(L"IDF_SETTINGS_SLEEP_LENGTH");
	return true;
}

result
FormSettingsSleepLength::OnInitializing(void)
{
	result r = E_SUCCESS;

	this->pScrollPanelSleepLength = static_cast<ScrollPanel*>(GetControl("IDC_SCROLLPANEL_SLEEP_LENGTH"));
	this->pValue5_00= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_5:00"));
	this->pValue5_30= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_5:30"));
	this->pValue6_00= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_6:00"));
	this->pValue6_30= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_6:30"));
	this->pValue7_00= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_7:00"));
	this->pValue7_30= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_7:30"));
	this->pValue8_00= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_8:00"));
	this->pValue8_30= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_8:30"));
	this->pValue9_00= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_9:00"));
	this->pValue9_30= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_9:30"));
	this->pValue10_00= static_cast<CheckButton*>(this->pScrollPanelSleepLength->GetControl("IDC_CHECKBUTTON_10:00"));

	this->pValue5_00->SetActionId(IDA_VALUE_5_00, IDA_VALUE_5_00);
	this->pValue5_30->SetActionId(IDA_VALUE_5_30, IDA_VALUE_5_30);
	this->pValue6_00->SetActionId(IDA_VALUE_6_00, IDA_VALUE_6_00);
	this->pValue6_30->SetActionId(IDA_VALUE_6_30, IDA_VALUE_6_30);
	this->pValue7_00->SetActionId(IDA_VALUE_7_00, IDA_VALUE_7_00);
	this->pValue7_30->SetActionId(IDA_VALUE_7_30, IDA_VALUE_7_30);
	this->pValue8_00->SetActionId(IDA_VALUE_8_00, IDA_VALUE_8_00);
	this->pValue8_30->SetActionId(IDA_VALUE_8_30, IDA_VALUE_8_30);
	this->pValue9_00->SetActionId(IDA_VALUE_9_00, IDA_VALUE_9_00);
	this->pValue9_30->SetActionId(IDA_VALUE_9_30, IDA_VALUE_9_30);
	this->pValue10_00->SetActionId(IDA_VALUE_10_00, IDA_VALUE_10_00);

	this->pValue5_00->AddActionEventListener(*this);
	this->pValue5_30->AddActionEventListener(*this);
	this->pValue6_00->AddActionEventListener(*this);
	this->pValue6_30->AddActionEventListener(*this);
	this->pValue7_00->AddActionEventListener(*this);
	this->pValue7_30->AddActionEventListener(*this);
	this->pValue8_00->AddActionEventListener(*this);
	this->pValue8_30->AddActionEventListener(*this);
	this->pValue9_00->AddActionEventListener(*this);
	this->pValue9_30->AddActionEventListener(*this);
	this->pValue10_00->AddActionEventListener(*this);

	//language
	this->SetTitleText(SCTranslator::GetText("IDS_SETTINGS_SLEEPLENGTH"));

	Footer* pFooter = this->GetFooter();
	FooterItem* pBack = new FooterItem();
	pBack->Construct(IDA_BUTTON_BACK);
	pBack->SetText(SCTranslator::GetText("IDS_ALARMS_BACK"));

	pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
	pFooter->AddItem(*pBack);

	pFooter->AddActionEventListener(*this);

	//Set default Value
	//this->Update();

	delete pBack;

	return r;
}

result
FormSettingsSleepLength::OnTerminating(void)
{
	result r = E_SUCCESS;
	return r;
}

void
FormSettingsSleepLength::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
{
	switch(actionId)
	{
		case IDA_BUTTON_BACK:
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_5_00:
			SCSettings::SetSleepLength(300);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_5_30:
			SCSettings::SetSleepLength(330);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_6_00:
			SCSettings::SetSleepLength(360);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_6_30:
			SCSettings::SetSleepLength(390);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_7_00:
			SCSettings::SetSleepLength(420);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_7_30:
			SCSettings::SetSleepLength(450);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_8_00:
			SCSettings::SetSleepLength(480);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_8_30:
			SCSettings::SetSleepLength(510);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_9_00:
			SCSettings::SetSleepLength(540);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_9_30:
			SCSettings::SetSleepLength(570);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
		case IDA_VALUE_10_00:
			SCSettings::SetSleepLength(500);
			SCFormManager::SwitchToForm(SCFormManager::IDF_SETTINGS, false, null, SCFormManager::SLIDE_RIGHT);
			break;
	}
}

int
FormSettingsSleepLength::GetFormId()
{
	return SCFormManager::IDF_SETTINGS_SLEEP_LENGTH;
}

void
FormSettingsSleepLength::SetChooseValue()
{
	this->pValue5_00->SetSelected(false);
	this->pValue5_30->SetSelected(false);
	this->pValue6_00->SetSelected(false);
	this->pValue6_30->SetSelected(false);
	this->pValue7_00->SetSelected(false);
	this->pValue7_30->SetSelected(false);
	this->pValue8_00->SetSelected(false);
	this->pValue8_30->SetSelected(false);
	this->pValue9_00->SetSelected(false);
	this->pValue9_30->SetSelected(false);
	this->pValue10_00->SetSelected(false);

	switch(SCSettings::GetSleepLength())
	{
		case 300:
			this->pValue5_00->SetSelected(true);
			break;
		case 330:
			this->pValue5_30->SetSelected(true);
			break;
		case 360:
			this->pValue6_00->SetSelected(true);
			break;
		case 390:
			this->pValue6_30->SetSelected(true);
			break;
		case 420:
			this->pValue7_00->SetSelected(true);
			break;
		case 450:
			this->pValue7_30->SetSelected(true);
			break;
		case 480:
			this->pValue8_00->SetSelected(true);
			break;
		case 510:
			this->pValue8_30->SetSelected(true);
			break;
		case 540:
			this->pValue9_00->SetSelected(true);
			break;
		case 570:
			this->pValue9_30->SetSelected(true);
			break;
		case 600:
			this->pValue10_00->SetSelected(true);
			break;
	}
}

void
FormSettingsSleepLength::Update()
{
	this->SetChooseValue();
	this->pScrollPanelSleepLength->ScrollToTop();
}

void
FormSettingsSleepLength::Redraw()
{
	this->Update();
	RequestRedraw(true);
}
